home *** CD-ROM | disk | FTP | other *** search
/ Aminet 2 / Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso / Aminet / dev / misc / egs.lha / EGS / EGS_Devels / Examples / EGS_Gadget / gadget.c < prev    next >
C/C++ Source or Header  |  1993-02-17  |  9KB  |  315 lines

  1. /*
  2. **  CHANGE          : 14. Jul 1992 mvk
  3. **                    17. Dez 1992 mvk
  4. **                    09  Jan 1993 mvk
  5. **
  6. **  This is an example of how to use context-sensitive gadgets.
  7. **
  8. **  It is like TeX: you create boxes and into the boxes
  9. **
  10. **  you put gadgets. The system will fit these gadgets
  11. **
  12. **  into the window for you. In this program you see
  13. **
  14. **  no absolute position of any gadget.
  15. **
  16. **
  17. **  (C) by VIONA Development 1991,1993
  18. **
  19. */
  20.  
  21. #include "includes.c"
  22.  
  23. EI_WindowPtr CreateGads (void);
  24.  
  25. struct Library *EGSIntuiBase;
  26. struct Library *EGBBase;
  27. struct Library *EGBScrollBase;
  28. struct Library *EGBRadioBase;
  29. struct Library *EGBSetBase;
  30. struct Library *EGBSelectBase;
  31. struct Library *EGBTextInfoBase;
  32.  
  33. EI_WindowPtr     window;
  34. EI_EIntuiMsgPtr  msg;
  35. EB_GadContext    con;
  36.  
  37. EB_StrArray    Texts = { "This is a demonstration",
  38.                          "of the gadbox.library !",
  39.                          "It supports all different ",
  40.              "types of gadgets which are ",
  41.              "scalable by sizing the window.", NULL };
  42.  
  43.  
  44. EB_StrArray    Gads1 = { " 8","13","18","24","40",NULL };
  45. EB_StrArray    Gads2 = { "OK","CANCEL",NULL };
  46. EB_StrArray2   Gadgs = { &Gads1, &Gads2, NULL };
  47.  
  48.  
  49. char infotext[] = "Information gadget:\n\n"
  50.                   "This is a text information gadget, it may provide"
  51.           "the user with helpful information about the program.\n"
  52.           "The gadget has an automatic wordwrap to allow different"
  53.           "font and box sizes, and is completely self handled.\n\n"
  54.           "This requester contains several different gadget types, "
  55.           "which are all created using the egsgadbox.library.\n";
  56.  
  57.  
  58. EI_WindowPtr CreateGads (void)
  59. {
  60.         EB_GadBoxPtr    root, help;
  61.         EI_GadgetPtr    tgad;
  62.  
  63.         con = EB_CreateGadContext(NULL,NULL,-1,-1);
  64.  
  65.         root = EB_CreateHorizBox(con);
  66.  
  67.         /*
  68.         ** Create vertical propgadget on the left side
  69.         */
  70.  
  71.         EB_AddLastSon(root, EB_CreateSuperVertiProp(con, 20, 4, 5, 0x2000,
  72.                                                     EB_DEC_UP_LEFT|EB_INC_BOTTOM_RIGHT ));
  73.  
  74.         EB_AddLastSon(root, EB_CreateHorizFill(con,0,0));
  75.  
  76.         help = EB_CreateVertiBox(con);
  77.  
  78.  
  79.         /*
  80.     **  Create a textbox on the top of the left side
  81.         */
  82.  
  83.         EB_AddLastSon(help, EB_CreateBackBorder(con,
  84.                             EB_CreateMultiText(con, &Texts),0));
  85.  
  86.         EB_AddLastSon(help, EB_CreateVertiFill(con,0,0));
  87.  
  88.         /*
  89.     **  Make some boolgadgets
  90.         */
  91.  
  92.         EB_AddLastSon(help, EB_CreateMultiAction2(con, &Gadgs,0x1000 ));
  93.  
  94.         EB_AddLastSon(help, EB_CreateVertiFill(con,0,0));
  95.  
  96.         EB_AddLastSon(help, EB_CreateSuperHorizProp(con, 20, 4, 5, 0x2001,
  97.                                                     EB_DEC_UP_LEFT|EB_INC_BOTTOM_RIGHT ));
  98.  
  99.         EB_AddLastSon(help, EB_CreateVertiFill(con,0,0));
  100.  
  101.         /*
  102.     **  Make two stringgadgrets
  103.         */
  104.  
  105.         EB_AddLastSon(help, EB_CreateNameStringGadget(con, "name", 20, 100,
  106.                                                       EI_JUSTIFY_LEFT, 0x3000));
  107.  
  108.         EB_AddLastSon(help, EB_CreateVertiFill(con,0,0));
  109.  
  110.         EB_AddLastSon(help, EB_CreateNameStringGadget(con, "path", 20, 100,
  111.                                                       EI_JUSTIFY_LEFT, 0x3000));
  112.  
  113.         EB_AddLastSon(help, EB_CreateVertiFill(con,0,0));
  114.  
  115.         /*
  116.     **  Create a scroll textbox
  117.         */
  118.  
  119.         EB_AddLastSon(help, EGB_CreateTextInfoGadget(con, 10, 40, 5, 10,
  120.                                                      NULL, 0x6000));
  121.  
  122.         EB_AddLastSon(root, help);
  123.  
  124.         EB_AddLastSon(root, EB_CreateHorizFill(con,0,0));
  125.  
  126.         EB_AddLastSon(root, EB_CreateSuperVertiProp(con, 20, 4, 5, 0x2002,
  127.                                                     EB_DEC_UP_LEFT|EB_INC_BOTTOM_RIGHT ));
  128.  
  129.         EB_AddLastSon(root, EB_CreateHorizFill(con,0,0));
  130.  
  131.         /*
  132.     ** Create a scrollbox with items (The items are appended in the main() function)
  133.         **
  134.         **  If the sort flag is set (TRUE),
  135.     **  the items will be inserted in alphabetical order.
  136.         */
  137.  
  138.         EB_AddLastSon(root, EGB_CreateLateScrollBox(con,20,40,10,20,TRUE,0x3000));
  139.  
  140.         EB_AddLastSon(root, EB_CreateHorizFill(con,0,0));
  141.  
  142.         help = EB_CreateHorizBox(con);
  143.  
  144.         /*
  145.     **  Create some radio boolgadgets (vertcial)
  146.         */
  147.  
  148.         EB_AddLastSon(help, EGB_CreateRadioGadget(con,&Gads1,100,0x4000));
  149.  
  150.         EB_AddLastSon(help, EB_CreateHorizFill(con,0,0));
  151.  
  152.         /*
  153.     ** Create some boolgadgets (vertical)
  154.         */
  155.  
  156.         EB_AddLastSon(help, EGB_CreateSetGadget(con,&Gads1,100,0x4001));
  157.  
  158.         EB_AddLastSon(root,help);
  159.  
  160.  
  161.  
  162.         if (EB_ProcessGadBoxes(con, root))
  163.           {
  164.  
  165.             tgad = EB_FindGadget(con->First, con->Num, 0x6000);
  166.  
  167.             if (tgad)
  168.               {
  169.                 EGB_ModifyTextInfoGadget(NULL, tgad, infotext);
  170.               }
  171.  
  172.             con->NewWin->IDCMPFlags         = EI_iCLOSEWINDOW;
  173.             con->NewWin->Bordef.SysGadgets |= (EI_WINDOWCLOSE);
  174.             con->NewWin->MaxWidth           = 800;
  175.             con->NewWin->MaxHeight          = 600;
  176.  
  177.             return (EI_OpenWindow(con->NewWin));
  178.           }
  179.         else
  180.           return NULL;
  181. }
  182.  
  183. void Crash (char * string)
  184. {
  185.         if (NULL != window)
  186.           EI_CloseWindow( window );
  187.  
  188.         if (NULL != con)
  189.           EB_DeleteGadContext(con);
  190.  
  191.         if (NULL != EGSIntuiBase)
  192.           CloseLibrary( EGSIntuiBase );
  193.  
  194.         if (NULL != EGBBase)
  195.           CloseLibrary( EGBBase );
  196.  
  197.         if (NULL != EGBScrollBase)
  198.           CloseLibrary( EGBScrollBase );
  199.  
  200.         if (NULL != EGBRadioBase)
  201.           CloseLibrary( EGBRadioBase );
  202.  
  203.         if (NULL != EGBSelectBase)
  204.           CloseLibrary( EGBSelectBase );
  205.  
  206.         if (NULL != EGBTextInfoBase)
  207.           CloseLibrary( EGBTextInfoBase );
  208.  
  209.         if (NULL == string)
  210.           exit (0);
  211.         else
  212.           {
  213.             printf ("%s.\n", string);
  214.             exit (10);
  215.           }
  216. }
  217.  
  218.  
  219.  
  220. void main (void)
  221. {
  222.  
  223.         struct Node     item1,item2,item3,item4;
  224.         EI_GadgetPtr    gad;
  225.  
  226.  
  227.         window  = NULL;
  228.         con     = NULL;
  229.  
  230.         EGSIntuiBase = OpenLibrary ( "egsintui.library", 0 );
  231.         if (NULL == EGSIntuiBase)
  232.           Crash ( "Could not open egsintui.library" );
  233.  
  234.         EGBBase = OpenLibrary ( "egsgadbox.library", 0 );
  235.         if (NULL == EGBBase)
  236.           Crash ( "Could not open egsgadbox.library" );
  237.  
  238.         EGBScrollBase = OpenLibrary ( "egb/gbscrollbox.library", 0 );
  239.         if (NULL == EGBScrollBase)
  240.           Crash ( "Could not open egb/gbscrollbox.library" );
  241.  
  242.         EGBRadioBase = OpenLibrary ( "egb/gbradio.library", 0 );
  243.         if (NULL == EGBRadioBase)
  244.           Crash ( "Could not open egb/gbradio.library" );
  245.  
  246.         EGBSetBase =  OpenLibrary ( "egb/gbsets.library", 0 );
  247.         if (NULL == EGBSetBase)
  248.           Crash ( "Could not open egb/gbsets.library" );
  249.  
  250.         EGBSelectBase = OpenLibrary ( "egb/gbselect.library", 0 );
  251.         if (NULL == EGBSelectBase)
  252.           Crash ( "Could not open egb/gbselect.library" );
  253.  
  254.         EGBTextInfoBase = OpenLibrary ( "egb/gbtextinfo.library", 0 );
  255.         if (NULL == EGBTextInfoBase)
  256.           Crash ( "Could not open egb/gbtextinfo.library" );
  257.  
  258.         window = CreateGads();
  259.  
  260.         gad = EB_FindGadget(con->First, con->Num, 0x3000);
  261.  
  262.         if(gad)
  263.         {
  264.  
  265.         /*
  266.         **  if Pri = 1 then the item is on top of the list
  267.     **  and highlighted (use of directories a.s.o)
  268.         */
  269.  
  270.  
  271.         item1.ln_Pri=0;
  272.         item2.ln_Pri=0;
  273.         item3.ln_Pri=0;
  274.         item4.ln_Pri=0;
  275.  
  276.         item1.ln_Name="d_Text1";
  277.         item2.ln_Name="b_Text2";
  278.         item3.ln_Name="a_Text3";
  279.         item4.ln_Name="c_Text4";
  280.  
  281.         EGB_AddItemToScrollBox(window, gad, &item1);
  282.         EGB_AddItemToScrollBox(window, gad, &item2);
  283.         EGB_AddItemToScrollBox(window, gad, &item3);
  284.         EGB_AddItemToScrollBox(window, gad, &item4);
  285.  
  286.         }
  287.  
  288.  
  289.               if (NULL == window)
  290.           Crash ("Could not open window");
  291.  
  292.         for (;;)
  293.           {
  294.  
  295.             while (NULL == (msg = (EI_EIntuiMsgPtr) GetMsg ( window->UserPort )))
  296.               WaitPort ( window->UserPort );
  297.  
  298.             switch (msg->Class)
  299.               {
  300.                 case EI_iCLOSEWINDOW:
  301.  
  302.                         ReplyMsg ( (struct Message*)msg );
  303.                         Crash (NULL);
  304.                         break;
  305.  
  306.                 default:
  307.                         printf (" Unknown message %ld\n", msg->Class);
  308.                         ReplyMsg ( (struct Message*)msg );
  309.               }
  310.  
  311.           }       /* forever */
  312.  
  313. }
  314.  
  315.